package top.zkh.login;

import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.java1234.dao.animalDao;
import com.java1234.dao.animaledDao;
import com.java1234.dao.carDao;
import com.java1234.model.animal;
import com.java1234.util.DbUtil;
public class cleanServlet extends HttpServlet{
	private DbUtil dbUtil=new DbUtil();
	private animaledDao animaleddao=new animaledDao();
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding ("utf-8");
		resp.setContentType("text/html;carset=utf-8");	
		List <String> mcars = new ArrayList<String>();
		mcars = (List)req.getSession().getAttribute("cars");
		List<animal> animal2 = new ArrayList<animal>();
		animal animal1 = new animal();
		animalDao animaldao = new animalDao();
		carDao cardao = new carDao();
		String ID = null;
		Connection con=null;
		try {
			con=dbUtil.getCon();
			for(int i=0;i<mcars.size();i++)
			{
				ID = mcars.get(i);
				animal1.setId((ID));
				animal2=animaldao.find1(con,animal1);
				for(animal animal3:animal2)
				{
					int n = animaldao.delete(con, animal3.getId());
					int c = cardao.delete(con, animal3.getId());
					int a = animaleddao.add(con, animal3.getAnimalType(), animal3.getPrice());
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		};
		
		req.getRequestDispatcher("userfind.jsp").forward(req, resp);
		}				
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(req, resp);
	}
}
